package adv5;

import java.io.File;
import java.util.LinkedList;

public class Digui {
	public static void a() {
		System.out.println("A");
		a();
	}

	// 计算阶乘 1*2...k
	public static long jiechen(int k) {
		if (k <= 1)
			return 1;
		return k * jiechen(k - 1);
	}

	// 返回斐波拉切的第n项
	// 前两项是1，后面的每一项是前两项的和
	public static long feibo(int n) {
		if (n <= 2)
			return 1;
		return feibo(n - 1) + feibo(n - 2);
	}

	public static void walk(File file) {
		if (file != null) {
			System.out.println(file.getAbsolutePath());
			if (file.isDirectory()) {
				// 列出全部的文件
				File f[] = file.listFiles();
				if (f != null)
					for (int i = 0; i < f.length; i++)
						// 递归调用自身
						walk(f[i]);
			}
		}
	}

	public static void walk2(File file) {
		// 暂存所有的文件夹
		LinkedList<File> list = new LinkedList<File>();
		list.add(file);
		while (list.size() > 0) {
			File t = list.removeFirst();
			System.out.println(t);
			if (t.canRead() == false)
				continue;

			if (t.isDirectory()) {
				File[] fr = t.listFiles();
				for (File f : fr) {
					if (f.isDirectory() == false)
						System.out.println(f);
					else
						list.addLast(f);
				}
			}
		}
	}

	public static void main(String[] args) {
		// a();
//		long l = jiechen(5);
//		System.out.println(l);
		walk2(new File("e:/资料"));
	}

}
